# Needs gawk, cut, cat, and grep. 
# Copy to a text file in a directory in your path. 
# Chmod it to executable. You need acpi compiled into your kernel or added as a module. This works for my toshiba satellite running 2.6.8 kernel. 
# Adjust if your device info gets put into /proc differently.
# Prints out the % of laptop battery remaining.

#/bin/bash
CAPACITY=`cat /proc/acpi/battery/BAT1/info | grep "last\ full\ capacity" | cut -d" " -f9`
CURRENT=`cat /proc/acpi/battery/BAT1/state | grep "remaining" | cut -d" " -f8`
PERCENT=`gawk -v CONVFMT="%12.2f" -v OFMT="%.5g"  "BEGIN { print $CURRENT / $CAPACITY * 100; }"`
echo Battery: $PERCENT%
